﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinformDevelopFrame.Common;
using WinformDevelopFrame.Core.Extend;
using WinformDevelopFrame.IServices;

namespace WinformDevelopFrame.UI
{
    public partial class FrmUpdatePassword : DevExpress.XtraEditors.XtraForm
    {
        private IsysuserService _userService;
        public FrmUpdatePassword(IsysuserService sysuserService)
        {
            _userService = sysuserService;
            InitializeComponent();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textEdit1.Text))
            {
                "请输入原密码".ShowTips();
                return;
            }

            if (!AppInfo.User.Password.Equals(textEdit1.Text))
            {
                "原始密码错误".ShowTips();
                return;
            }
            if (string.IsNullOrEmpty(textEdit2.Text))
            {
                "请输入新密码".ShowTips();
                return;
            }
            if (!textEdit2.Text.Equals(textEdit3.Text))
            {
                "两次新密码不一致".ShowTips();
                return;
            }
            AppInfo.User.Password=textEdit2.Text;
            if (_userService.UpdateN(AppInfo.User))
            {
                "修改成功".ShowTips();
            }
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}